package com.lhk.appframework.manager;

import com.lhk.appframework.utils.UtilsSP;

import android.content.Context;

public class ImplManagerSharedPreferences extends BaseManager implements ManagerSharedPreferences{

	private static ImplManagerSharedPreferences instance = null;
	private ImplManagerSharedPreferences(Context context) {
		this.context = context;
	}
	
	public static ImplManagerSharedPreferences getInstance(Context context){
		if(instance == null){
			synchronized (ImplManagerSharedPreferences.class) {
				if(instance == null){
					instance = new ImplManagerSharedPreferences(context);
				}
			}
		}
		return instance;
	}
	
	private Context context;
	
	
	@Override
	public void put(Context context, String fileName, String key, Object object) {
		String privateFileName = translate2PrivateFileName(fileName);
		UtilsSP.put(context, privateFileName, key, object);
	}

	@Override
	public Object get(Context context, String fileName, String key, Object defaultObject) {
		String privateFileName = translate2PrivateFileName(fileName);
		return UtilsSP.get(context, privateFileName, key, defaultObject);
	}

	@Override
	public void put(Context context, String key, Object object) {
		String fileName = getDefaultSPFileName();
		String privateFileName = translate2PrivateFileName(fileName);
		put(context, privateFileName, key, object);
	}

	@Override
	public Object get(Context context, String key, Object defaultObject) {
		String fileName = getDefaultSPFileName();
		String privateFileName = translate2PrivateFileName(fileName);
		return get(context, privateFileName, key, defaultObject);
	}
	
	private String getDefaultSPFileName(){
		return ManagerSharedPreferences.SPNAME;
	}
	private String getUserID(){
		return "";
	}
	private String translate2PrivateFileName(String fileName){
		String userID = getUserID();
		String privateFileName = userID + fileName;
		return privateFileName;
	}
	
}
